<template>
    <view>
        <view style="height: 100rpx"></view>
        <view class="cart-bar padding-lr-base">
            <view class="content flex align-center justify-between">
                <view class="flex align-center">
                    <customCheckbox v-model="cartStore.isAll" size="35rpx" @change="selectAll"></customCheckbox>
                    <view class="text-grey">全选</view>
                </view>
                <view class="flex align-center">
                    <view v-if="!cartStore.isUpdate" class="flex align-center">
                        <view>合计：</view>
                        <view class="text-red text-bold">
                            <text>￥</text>
                            <text class="text-xl">{{ cartStore.cartCheckMoney }}</text>
                        </view>
                    </view>
                    <button v-if="!cartStore.isUpdate" class="padding-lr-base bg-main round text-base margin-left-base" style="width: 200rpx">
                        结算
                    </button>
                    <button v-else @click="delSku" class="padding-lr-base bg-main round text-base margin-left-base" style="width: 200rpx">
                        删除
                    </button>
                </view>
            </view>
        </view>
    </view>
</template>

<script lang="ts" setup>
import customCheckbox from "../input/custom-checkbox.vue";

import { ref } from "vue";
import { useModal } from "@/utils/message";
import { useCartStore } from "@/store/module/cart";

const cartStore = useCartStore();

const selectAll = (is_check: boolean) => {
    let ids: any[] = [];
    cartStore.cartList.forEach((company: any) => {
        company.list.forEach((sku: any) => {
            ids.push(sku.id);
        });
    });
    cartStore.selectProduct(ids, is_check, true);
};

const delSku = async () => {
    await useModal("温馨提示", "确定要删除选中商品吗？", "确定", "取消");
    let ids: any[] = [];
    cartStore.cartList.forEach((company: any) => {
        company.list.forEach((sku: any) => {
            if (sku.isCheck) {
                ids.push(sku.id);
            }
        });
    });
    cartStore.removeSku(ids);
};
</script>

<style lang="scss" scoped>
.cart-bar {
    position: fixed;
    left: 0;
    right: 0;
    background-color: #fff;
    /* #ifdef H5 */
    bottom: 50px;
    /* #endif */
    /* #ifndef H5 */
    bottom: 0;
    /* #endif */
    z-index: 99;
    border-radius: 5% 5% 0 0;
    border-bottom: 1px solid #eee;

    .content {
        height: 100rpx;
    }
}
</style>
